<template>
    <div class="customer-list">
      <span style="font-size: 30px;position: relative; top: -10px ;">订单入库</span>
      <!-- 这里放置表格等内容 -->
        <div class="add-button-bottom-right">
          <el-button type="primary" icon="el-icon-loading" @click="handleAudit">审核</el-button>
          <el-button class="delete-button" type="danger" icon="el-icon-delete"  @click="handleDeleteSelected">删除</el-button>
          <el-button icon="el-icon-check" class="add-button"  @click="showAddModall">新增入库订单</el-button>
        </div>
        <div style="display: flex; align-items: center;">
            <!-- 搜索框 -->
           <el-input style="width: 300px; margin: 10px 20px 10px 0;"  placeholder="请输入" prefix-icon="el-icon-search" v-model="OrderWord" @change="PurFenYe"></el-input>
            <!-- 日期选择器 -->
            <el-date-picker  type="date" placeholder="选择日期" v-model="SelectedDate" @change="PurFenYe"></el-date-picker>
        </div>
         <el-divider></el-divider>
           <div id="bodydiv">
            <el-table :data="warehousing"  border style="width: 100%" class="centered-table" @selection-change="handleSelectionChange"> 
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="pw_number" label="生产订单编号"></el-table-column>
            <el-table-column prop="pw_code" label="客户姓名"></el-table-column>
            <el-table-column prop="pw_client_property" label="客户属性"></el-table-column>
            <el-table-column prop="pw_types" label="商品种类">  
            <template slot-scope="scope"> 
              {{ scope.row.pw_types }} 种
            </template>
        </el-table-column>
        <el-table-column prop="pw_state" label="订单状态" width="auto">
            <template slot-scope="scope">
              <span
                :style="{
                    color: scope.row.pw_state == 1   ? '#2ab600' : 'red',
                }"
              >{{ scope.row.pw_state == 1 ? '已完成' : '未完成' }}</span>
            </template>      
        </el-table-column>

        <el-table-column prop="pw_warehouse" label="入库状态">
            <template slot-scope="scope">
              <span
              :style="{
                color:
                  scope.row.pw_warehouse == 0
                    ? 'red'
                    : scope.row.pw_warehouse == 1
                    ? 'orange'
                    : '#2ab600',
              }"
            >
              {{
                scope.row.pw_warehouse == 0
                  ? "未入库"
                  : scope.row.pw_warehouse == 1
                  ? "待入库"
                  : "已入库"
              }}
            </span>
            </template>
        </el-table-column>
        <el-table-column prop="AuditStatus" label="审核状态" width="auto">
        <template slot-scope="scope">
            <span
              :style="{
                color: scope.row.auditStatus == true ? '#2ab600' : 'red',
              }"
            >
              {{ scope.row.auditStatus == true ? "已审核" : "未审核" }}
            </span>
          </template>
        </el-table-column>

        <el-table-column prop="pw_storage_date" label="入库日期">
            <template slot-scope="scope">
              <span>{{ formatDate(scope.row.pw_storage_date) }}</span>
            </template>
        </el-table-column>
        <el-table-column label="操作" width="150">
            <template slot-scope="scope">
              <el-button size="mini" type="primary" icon="el-icon-edit" @click="editCustomers(scope.row)">查看</el-button>
            </template>
        </el-table-column>
         </el-table>
           </div>
      <el-divider></el-divider> <!-- 下划线分隔 -->
      <!-- 分页 -->
      <div>
        <el-pagination class="pagination"
            @size-change="Change"
            @current-change="YmChange"
            :current-page="currentPage"
            :page-sizes="[5, 10, 20, 50]" 
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper" 
            :total="rows">
        </el-pagination>
      </div>
      <!-- 主新增 -->
     <el-dialog :visible.sync="isAddModalVisible" class="addmodel" width="70%" :before-close="PurHandleClose">
            <div class="custom-div1">
                <el-button @click="PurOrderAdd">提交新增</el-button>
            </div>
            <div class="custom-div">
                <span>新增入库订单</span>
            </div>
            <el-button class="orange-button" style="position: absolute; top: 43px; left: 10; padding: 10px;"
                @click="returnToList">返回列表</el-button>
            <el-form :model="PurAdd" class="custom-form" label-position="top">
                <div class="form-items-container">
                    <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;">
                        <div style="display: flex; align-items: center;">
                            <label style="width: 80px; margin-right:-12px;">客户姓名:</label>
                            <el-select v-model="PurAdd.pw_code" auto-complete="off" placeholder="请选择" style="flex: 1; size:large">
                                <el-option 
                                  v-for="item in listName" 
                                  :key="item.client_head" style="width: 100%;"
                                  :label="item.pw_code" 
                                  :value="item.client_head" class="kuang">
                                </el-option>
                            </el-select>
                        </div>
                         <div>
                        <div style="display: flex; align-items: center;">
                            <label style="width:80px; margin-right:-12px;">客户属性:</label>
                            <el-select v-model="PurAdd.pw_client_property" auto-complete="off" placeholder="请选择" style="flex: 1; size:large">
                                <el-option 
                                  v-for="item in list2" 
                                 :key="item.dd_label" style="width: 100%;"
                                 :label="item.pw_client_property" 
                                  :value="item.dd_label" class="kuang">
                                </el-option>
                            </el-select>
                        </div>
                         </div>
                        <div style="display: flex; align-items: center;">
                            <label style="width: 80px; margin-right: -10px;" disabled >订单编号:</label>
                            <el-input v-model="PurAdd.pw_number" auto-complete="off" style="flex: 1;" placeholder="" class="kuang" readonly disabled ></el-input>
                        </div>
                        <div style="display: flex; align-items: center;">
                            <label style="width: 80px; margin-right:-10px;">操作人员:</label>
                            <el-select v-model="PurAdd.pw_operators" auto-complete="off" placeholder="请选择" style="flex: 1; size:large" @change="onCustomerContactChange($event)">
                                <el-option 
                                  v-for="item in OpersGou" 
                                  :key="item.employee_name" style="width: 100%;"
                                  :label="item.pw_operators" 
                                  :value="item.employee_name" class="kuang">
                                </el-option>
                            </el-select>
                        </div>

                        <div style="display: flex; align-items: center;">
                            <label style="width: 80px; margin-right: -12px;">入库日期:</label>
                            <el-date-picker v-model="PurAdd.pw_storage_date" auto-complete="off" style="flex: 1;" class="kuang" ></el-date-picker>
                        </div>
                    </div>
                </div>
                <div style="border-bottom: 1px solid #e0e0e0; margin-top:20px;"></div>
                <div class="button-container">
                    <el-button @click="PurFromAdd" class="custom-button"  style="border:none;">添加</el-button>
                </div>
                <!-- 入库列表 -->
                <div class="product-list-container">
                    <el-table :data="allData" style="width: 100%" border >
                           <el-table-column prop="wf_id" type="index" label="序号" width="80"></el-table-column>
                           <el-table-column prop="wf_sing_model" label="产品型号"></el-table-column>
                           <el-table-column prop="wf_redserial_number" label="产品名称"></el-table-column>
                           <el-table-column prop="wf_redunit" label="单位" width="100"></el-table-column>
                           <el-table-column prop="wf_storage" label="入库数量"></el-table-column>
                           <el-table-column prop="wf_raw_material" label="生产原料"></el-table-column>
                           <el-table-column prop="wf_inbound_warehouse" label="入库仓库"></el-table-column>
                            <el-table-column label="操作"  width="200">
                            <template>
                                <el-button class="caoz" size="mini" type="danger" icon="el-icon-delete"
                                  @click="deleteCustomer(index)">删除
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                     <div style="border-bottom: 1px solid #e0e0e0; margin-top:50px; margin-left:10px; width: 100%;"></div>
                </div>
              <div class="pagination-wrapper">
                <el-pagination
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="currentPage1"
                  :page-sizes="[3,6,9,12]"
                  :page-size="pageSize1"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="totalItems">
                </el-pagination>
              </div>
            </el-form>
        </el-dialog>
         <!-- 从-生产订单从添加 -->
        <el-dialog title="添加" :visible.sync="isAddProductVisible" width="400px" class="qw">
            <el-form label-width="300px">
                <el-form-item label="产品型号" style="position: relative; margin-left:-180px; top: -20px;">
                    <el-select v-model="from.wf_sing_model" placeholder="请选择" style="width: 180px;" @change="ContactChange($event)">
                        <el-option 
                         v-for="item in listName2"
                         :key="item.di_name"
                          :label="item.wf_sing_model"
                         :value="item.di_name">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="产品名称" style="position: relative; margin-left:-180px; top: -20px;">
                    <el-input v-model="from.wf_redserial_number" placeholder="请选择" style="width: 180px;">
                    </el-input>
                </el-form-item>
                <el-form-item label="单位" style="position: relative; margin-left:-180px; top: -20px;">
                    <el-select v-model="from.wf_redunit" placeholder="请选择" style="width: 180px;">
                        <el-option 
                          v-for="item in units" 
                          :key="item.dd_label" 
                          :label="item.wf_redunit"
                          :value="item.dd_label">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="入库仓库" style="position: relative; margin-left:-180px; top: -20px;">
                    <el-select v-model="from.wf_inbound_warehouse" placeholder="请选择" style="width: 180px;">
                        <el-option 
                          v-for="item in Wareh" 
                          :key="item.w_Name" 
                          :label="item.wf_inbound_warehouse"
                          :value="item.w_Name">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="生产入库数量" style="position: relative;  margin-left:-180px; top: -20px;">
                    <el-input-number v-model="from.wf_storage" :min="1" :step="1" controls-position="right"></el-input-number>
                </el-form-item>
                 
                  <el-form-item label="生产原料用量" style="position: relative;  margin-left:-180px; top: -20px;">
                    <el-input-number v-model="from.wf_raw_material" :min="1" :step="1" controls-position="right"></el-input-number>
                </el-form-item>
            </el-form>
            <div>
                <span slot="footer" style="display: flex; justify-content: center;">
                    <el-button @click="isAddProductVisible = false"
                        style="margin-left:20px; background-color: #4FC1B0; border-color: #4FC1B0; color: #fff;">取消</el-button>
                    <el-button type="primary" @click="SubmitModelForm"
                        style="margin-left: 10px; background-color: #4FC1B0; border-color: #4FC1B0; color: #fff;">确定</el-button>
                </span>
            </div>
        </el-dialog>
       <!-- 主修改 -->
      <el-dialog :visible.sync="isUpdateModalVisible" class="addmodel" width="70%">
            <div class="custom-div1">
                <el-button @click="PurOrderUpdate">提交修改</el-button>
            </div>
            <div class="custom-div">
                <span>新增入库订单</span>
            </div>
            <el-button class="orange-button" style="position: absolute; top: 43px; left: 10; padding: 10px;"
                @click="returnToList">返回列表</el-button>
            <el-form :model="ReceiptUpdate" class="custom-form" label-position="top">
                <div class="form-items-container">
                    <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;">
                        <div style="display: flex; align-items: center;">
                            <label style="width: 80px; margin-right:-12px;">客户姓名:</label>
                            <el-select v-model="ReceiptUpdate.pw_code" auto-complete="off" placeholder="请选择" style="flex: 1; size:large">
                                <el-option 
                                  v-for="item in listName" 
                                  :key="item.client_head" style="width: 100%;"
                                  :label="item.pw_code" 
                                  :value="item.client_head" class="kuang">
                                </el-option>
                            </el-select>
                        </div>
                         <div>
                        <div style="display: flex; align-items: center;">
                            <label style="width:80px; margin-right:-12px;">客户属性:</label>
                            <el-select v-model="ReceiptUpdate.pw_client_property" auto-complete="off" placeholder="请选择" style="flex: 1; size:large">
                                <el-option 
                                  v-for="item in list2" 
                                 :key="item.dd_label" style="width: 100%;"
                                 :label="item.pw_client_property" 
                                  :value="item.dd_label" class="kuang">
                                </el-option>
                            </el-select>
                        </div>
                         </div>
                        <div style="display: flex; align-items: center;">
                            <label style="width: 80px; margin-right: -10px;" disabled >订单编号:</label>
                            <el-input v-model="ReceiptUpdate.pw_number" auto-complete="off" style="flex: 1;" placeholder="" class="kuang" readonly disabled ></el-input>
                        </div>
                        <div style="display: flex; align-items: center;">
                            <label style="width: 80px; margin-right:-10px;">操作人员:</label>
                            <el-select v-model="ReceiptUpdate.pw_operators" auto-complete="off" placeholder="请选择" style="flex: 1; size:large" @change="onCustomerContactChange($event)">
                                <el-option 
                                  v-for="item in OpersGou" 
                                  :key="item.employee_name" style="width: 100%;"
                                  :label="item.pw_operators" 
                                  :value="item.employee_name" class="kuang">
                                </el-option>
                            </el-select>
                        </div>
                        <div style="display: flex; align-items: center;">
                            <label style="width: 80px; margin-right: -12px;">入库日期:</label>
                            <el-date-picker v-model="ReceiptUpdate.pw_storage_date" auto-complete="off" style="flex: 1;" class="kuang" ></el-date-picker>
                        </div>
                    </div>
                </div>
                <div style="border-bottom: 1px solid #e0e0e0; margin-top:20px;"></div>
                <div class="button-container">
                    <el-button @click="PurFromUpdate" class="custom-button"  style="border:none;">添加</el-button>
                </div>
                <!-- 入库列表 -->
                <div class="product-list-container">
                    <el-table :data="chaseFrom" style="width: 100%" border >
                           <el-table-column prop="wf_id" type="index" label="序号" width="80"></el-table-column>
                           <el-table-column prop="wf_sing_model" label="产品型号"></el-table-column>
                           <el-table-column prop="wf_redserial_number" label="产品编号"></el-table-column>
                           <el-table-column prop="wf_redunit" label="单位" width="80"></el-table-column>
                           <el-table-column prop="wf_storage" label="入库数量"></el-table-column>
                           <el-table-column prop="wf_raw_material" label="生产原料"></el-table-column>
                           <el-table-column prop="wf_inbound_warehouse" label="入库仓库"></el-table-column>
                            <el-table-column label="操作"  width="200">
                            <template slot-scope="scope" >
                               <el-button class="caoz" size="mini" type="primary" icon="el-icon-edit"
                                  @click="UpdatePurEditFrom(scope.row)">修改</el-button>
                                <el-button class="caoz" size="mini" type="danger" icon="el-icon-delete"
                                   @click="UpdatedeleteCustomer(scope.row.wf_id)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                     <div style="border-bottom: 1px solid #e0e0e0; margin-top:50px; margin-left:10px; width: 100%;"></div>
                </div>
              <div class="pagination-wrapper">
                <el-pagination
                 @size-change="UdateSizeChange"
                  @current-change="UpdateCurrentChange"
                  :current-page="currentPage2"
                  :page-sizes="[3,6,9,12]"
                  :page-size="pageSize2"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="UpdateItems">
                </el-pagination>
              </div>
            </el-form>
        </el-dialog>

         <!-- 从-添加 -->
        <el-dialog title="添加" :visible.sync="isUpdateProductVisible" width="400px" class="qw">
            <el-form label-width="300px">
                <el-form-item label="产品型号" style="position: relative; margin-left:-180px; top: -20px;">
                    <el-select v-model="EditUpdate.wf_sing_model" placeholder="请选择" style="width: 180px;" @change="ContactChange($event)">
                        <el-option 
                         v-for="item in listName2"
                         :key="item.di_name"
                          :label="item.wf_sing_model"
                         :value="item.di_name">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="产品名称" style="position: relative; margin-left:-180px; top: -20px;">
                    <el-input v-model="EditUpdate.wf_redserial_number" placeholder="请选择" style="width: 180px;">
                    </el-input>
                </el-form-item>
                <el-form-item label="单位" style="position: relative; margin-left:-180px; top: -20px;">
                    <el-select v-model="EditUpdate.wf_redunit" placeholder="请选择" style="width: 180px;">
                        <el-option 
                          v-for="item in units" 
                          :key="item.dd_label" 
                          :label="item.wf_redunit"
                          :value="item.dd_label">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="入库仓库" style="position: relative; margin-left:-180px; top: -20px;">
                    <el-select v-model="EditUpdate.wf_inbound_warehouse" placeholder="请选择" style="width: 180px;">
                        <el-option 
                          v-for="item in Wareh" 
                          :key="item.w_Name" 
                          :label="item.wf_inbound_warehouse"
                          :value="item.w_Name">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="生产入库数量" style="position: relative;  margin-left:-180px; top: -20px;">
                    <el-input-number v-model="EditUpdate.wf_storage" :min="1" :step="1" controls-position="right"></el-input-number>
                </el-form-item>
                 
                  <el-form-item label="生产原料用量" style="position: relative;  margin-left:-180px; top: -20px;">
                    <el-input-number v-model="EditUpdate.wf_raw_material" :min="1" :step="1" controls-position="right"></el-input-number>
                </el-form-item>
            </el-form>
            <div>
                <span slot="footer" style="display: flex; justify-content: center;">
                    <el-button @click="isUpdateProductVisible = false"
                        style="margin-left:20px; background-color: #4FC1B0; border-color: #4FC1B0; color: #fff;">取消</el-button>
                    <el-button type="primary" @click="FromUpdateSubmit"
                        style="margin-left: 10px; background-color: #4FC1B0; border-color: #4FC1B0; color: #fff;">确定</el-button>
                </span>
            </div>
        </el-dialog>
        
         <!-- 从-修改 -->
        <el-dialog title="添加" :visible.sync="isUpdateProduct" width="400px" class="qw">
            <el-form label-width="300px">
                <el-form-item label="产品型号" style="position: relative; margin-left:-180px; top: -20px;">
                    <el-select v-model="FromEditUpdate.wf_sing_model" placeholder="请选择" style="width: 180px;" @change="ContactChange($event)">
                        <el-option 
                         v-for="item in listName2"
                         :key="item.di_name"
                          :label="item.wf_sing_model"
                         :value="item.di_name">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="产品名称" style="position: relative; margin-left:-180px; top: -20px;">
                    <el-input v-model="FromEditUpdate.wf_redserial_number" placeholder="请选择" style="width: 180px;">
                    </el-input>
                </el-form-item>
                <el-form-item label="单位" style="position: relative; margin-left:-180px; top: -20px;">
                    <el-select v-model="FromEditUpdate.wf_redunit" placeholder="请选择" style="width: 180px;">
                        <el-option 
                          v-for="item in unitss" 
                          :key="item.dd_label" 
                          :label="item.wf_redunit"
                          :value="item.dd_label">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="入库仓库" style="position: relative; margin-left:-180px; top: -20px;">
                    <el-select v-model="FromEditUpdate.wf_inbound_warehouse" placeholder="请选择" style="width: 180px;">
                        <el-option 
                          v-for="item in Warehs" 
                          :key="item.w_Name" 
                          :label="item.wf_inbound_warehouse"
                          :value="item.w_Name">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="生产入库数量" style="position: relative;  margin-left:-180px; top: -20px;">
                    <el-input-number v-model="FromEditUpdate.wf_storage" :min="1" :step="1" controls-position="right"></el-input-number>
                </el-form-item>
                 
                  <el-form-item label="生产原料用量" style="position: relative;  margin-left:-180px; top: -20px;">
                    <el-input-number v-model="FromEditUpdate.wf_raw_material" :min="1" :step="1" controls-position="right"></el-input-number>
                </el-form-item>
            </el-form>

              <el-form-item label="外键Id" style="position: relative;  margin-left:-180px; top: 10px;" v-if="Ycchange">
                   <el-input v-model="FromEditUpdate.pro_warehousingpw_id" v-if="Ycchange"></el-input>
                 </el-form-item> 
            <div>
                <span slot="footer" style="display: flex; justify-content: center;">
                    <el-button @click="isUpdateProduct = false"
                        style="margin-left:20px; background-color: #4FC1B0; border-color: #4FC1B0; color: #fff;">取消</el-button>
                    <el-button type="primary" @click="FromUpdatePur"
                        style="margin-left: 10px; background-color: #4FC1B0; border-color: #4FC1B0; color: #fff;">确定</el-button>
                </span>
            </div>
        </el-dialog>
    
        </div>
</template>
<script>
import $http from '@/routers/base';
import { MessageBox } from 'element-ui';
import moment from 'moment'; 
export default {
    data(){
        return{
             auditStatus: "",
             index: 0,
             total:[],

            OrderWord:"",//搜索框
            SelectedDate:"",//时间搜索框
            DateString:'',//时间转型
           
           
           
            warehousing:[],
            currentPage: 1, //当前页
            pageSize: 5, //每页显示数
            rows: 0, //总行数
           
           currentPage1: 1, //当前页
           pageSize1: 3, //每页显示数
           totalItems: 0, //总行数

           chaseFrom:[],
           currentPage2: 1, //当前页
           pageSize2: 5, //每页显示数
           UpdateItems: 0, //总行数
           SelectPurChaseID:0,
           
            isAddModalVisible:false,
            isUpdateModalVisible:false,
            isAddProductVisible:false,
            isUpdateProductVisible:false,//添加
            isUpdateProduct:false,//修改

            list2:[],//商品属性
            list3:[],//商品名称
            units:[],//单位
            Wareh:[],//入库仓库
            unitss:[],//单位
            Warehs:[],//入库仓库

            PurAdd:{
              pw_code:'',
              pw_client_property:'',
              pw_number:'',
              pw_storage_date:'',
              pw_operators:'',
              auditStatus:'',
              pw_state:'0',
              pw_warehouse:'0',
              auditStatus:'',
              IsDeleted:"",
            },

          from:{
            wf_sing_model:"",//产品属性
            wf_redserial_number:"",////产品名称
            wf_redunit:"",//单位
            wf_storage:"",//生产入库数量
            wf_inbound_warehouse:"",//入库仓库
            wf_raw_material:"",//生产原料用量

            pro_warehousingpw_id:"",
        },

         ReceiptUpdate:{
              pw_id:'',
              pw_code:'',
              pw_client_property:'',
              pw_number:'',
              pw_storage_date:'',
              pw_operators:'',
              auditStatus:'',
              pw_state:'0',
              pw_warehouse:'0',
              IsDeleted:"",
              auditStatus: "",
         },
         FromEditUpdate:{
            wf_id:'',
            wf_sing_model:"",//产品属性
            wf_redserial_number:"",////产品名称
            wf_redunit:"",//单位
            wf_storage:"",//生产入库数量
            wf_inbound_warehouse:"",//入库仓库
            wf_raw_material:"",//生产原料用量

            pro_warehousingpw_id:'',
         },

          EditUpdate:{
            wf_sing_model:"",//产品属性
            wf_redserial_number:"",////产品名称
            wf_redunit:"",//单位
            wf_storage:"",//生产入库数量
            wf_inbound_warehouse:"",//入库仓库
            wf_raw_material:"",//生产原料用量

            pro_warehousingpw_id:"",
          },

          testArr:{},

               allData:[],
               listName:[],
               listName2:[],
               OpersGou:[],
               selectedRows:[],
               Ycchange:"",
        }
        
    },
    computed: {
      uniqueList() {
      // 利用Set数据结构对数组进行去重
      const uniqueValues = [...new Set(this.list2.map(item => item.di_type))];
      // 根据去重后的值构造对象数组
      const uniqueList = uniqueValues.map(value => ({
        di_type: value,
      }));
      return uniqueList;
      },
  },
    methods: {
    //选中行
    handleSelectionChange(selection) {
      this.selectedRows = selection; // 更新选中的行
    },
    //复选框删除 
   handleDeleteSelected(){
      if (this.selectedRows.length === 0) {
        this.$message.warning("请至少选择一个进行删除");
        return;
      }
      // 检查选中的订单中是否有已经审核通过的（audit_status === true）
      const auditedRows = this.selectedRows.filter(
        (row) => row.auditStatus === true
      );
      if (auditedRows.length > 0) {
        this.$message.warning(
          "选中的采购订单中已有部分订单已经审核通过，不能删除数据"
        );
        return;
      }
      this.$confirm("此操作将删除选中的销售订单, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
      .then(() => {
          this.selectedRows.forEach((row) => {
            this.deleteCustomers(row.pw_id);
          });
          this.PurFenYe();
          this.selectedRows = [];
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //逻辑删除方法
    deleteCustomers(pw_id){
      $http
        .delete(`WareHousing/WareDelete/${pw_id}`)
        .then((response) => {
          this.$message({
            message: response,
            type: "success",
          });
          this.PurFenYe();
        })
        .catch((error) => {
          this.$message.error("删除失败，请稍后再试");
          console.error("Delete error:", error);
      });
    },
     //审核
    handleAudit() {
      if (this.selectedRows.length === 0) {
        this.$message.warning("请至少选择一个采购订单进行审核");
        return;
      }

      // 检查选中的订单中是否有已经审核通过的（audit_status === true）
      const auditedRows = this.selectedRows.filter(
        (row) => row.auditStatus === true
      );
      if (auditedRows.length > 0) {
        this.$message.warning(
          "选中的采购入库单中已有部分已经审核通过，不能再次审核"
        );
        return;
      }

      this.$confirm("此操作将审核选中的采购入库单, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.selectedRows.forEach((row) => {
            this.auditSaleOrder(row.pw_id);
          });
          this.selectedRows = [];
          this.PurFenYe();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消审核",
          });
        });
    },
    //审核方法
    auditSaleOrder(pw_id) {
      $http
        .post(`WareHousing/AuditSalesReturn/${pw_id}`)
        .then((response) => {
          this.$message({
            message: response,
            type: "success",
          });
          this.PurFenYe();
        })
        .catch((error) => {
          this.$message.error("审核失败，请稍后再试");
          console.error("Audit error:", error);
        });
    },
    //日期转型
    formatDate(dateString) {
            if (!dateString) {
                return '';
            }
            const date = new Date(dateString);
            if (isNaN(date.getTime())) {
                return '';
            }
            const year = date.getFullYear();
            const month = (date.getMonth() + 1).toString().padStart(2, '0');
            const day = date.getDate().toString().padStart(2, '0');
            return `${year}-${month}-${day}`;
    },
    //分页查询
    PurFenYe(){
        this.DateString = moment(this.SelectedDate).format('YYYY-MM-DD');
        this.where="1=1"
        if(this.OrderWord){
          this.where +=`and (pw_number like '%${this.OrderWord}%' or pw_code like '%${this.OrderWord}%' or pw_operators like '%${this.OrderWord}%')`
        }
        if(this.OrderDate){
          this.where += ` AND pw_storage_date = '${this.OrderDate}'`;
        }
        if(this.SelectedDate){
          this.where +=`and (CAST(pw_storage_date AS DATE) ='${this.DateString}')`
        }
        $http.get('WareHousing/getFenYe',{
            params:{
                currentPage: this.currentPage,
                pageSize: this.pageSize,
                where:this.where,
            }
        }).then(res=>{
            this.warehousing=res.warehousing;
            this.rows=res.rows;
        }).catch(error=>{
            console.error('Error fetching client data: ', error);
        })
    },
    Change: function(size) {
      this.pageSize = size;
      this.currentPage = 1;
      this.PurFenYe();
    },
    YmChange: function(page) {
      this.currentPage = page;
      this.PurFenYe();
    },
     // 显示新增客户弹窗
    showAddModall(){
        this.isAddModalVisible=true;
    },
     returnToList() {
       this.isAddModalVisible = false; // 返回列表
       this.isUpdateModalVisible=false
    },
     //查询客户属性
    fetch(){
      $http
        .get("ProRders/Queryclient")
          .then(res=>{
            this.list2 = res;
          })
          .catch(err => {
            alert(err);
          });
    },
     //查询客户名称
     GouPur(){
      $http.get('ProRders/ClientIndex')
          .then(res=>{
            this.listName=res;
          })
          .catch(err=>{
            alert(err);
          });
    },
    //单位下拉
    fetchUnits() {
      $http.get('dict_data/Queryunit')
        .then((res) => {
          // 根据type属性过滤出单位数据
          this.units = res
          this.unitss = res
          this.units.forEach((unit) => {
          console.log(unit.dd_label);
          });
        })
        .catch((error) => {
            console.error('Error fetching units from dictionary:', error);
        });
    },
    //查询操作人员
    Opers(){
      $http.get("Employee/Query")
        .then(res=>{
          this.OpersGou=res;
        })
        .catch(err=>{
          alert(err);
        });
    },
    //查询产品名称
    ImgerFrom(){
      $http
        .get("BsModel/DictImagQuery")
          .then(res=>{
            this.listName2 = res;
          })
          .catch(err => {
            alert(err);
          });
    },
    // 当产品名称选择变化时触发
      ContactChange(selectedContact) {
          const contactInfo = this.listName2.find(
              (c) => c.di_name === selectedContact
          );
          if (contactInfo) {
             this.from.wf_redserial_number = contactInfo.di_code;
              this.EditUpdate.wf_redserial_number=contactInfo.di_code;
             this.FromEditUpdate.wf_redserial_number=contactInfo.di_code;

          }
      },
    //入库仓库
    WarehAit(){
      $http.get('InventoryAlerts/IQuery')
        .then((res) => {
          // 根据type属性过滤出单位数据
          this.Wareh = res
          this.Warehs= res
          this.Wareh.forEach((unit) => {
          console.log(unit.dd_label);
          });
        })
        .catch((error) => {
            console.error('Error fetching units from dictionary:', error);
        });
    },
    //生产订单-修改框
    editCustomers(row){
         this.isUpdateModalVisible = true;
         this.SelectPurChaseID=row.pw_id;
         this.ReceiptUpdate.pro_warehousingpw_id=this.SelectPurChaseID;
         this.fetchUpaheModeFrom();
         this.fetchUnits();
         this.WarehAit();
         this.$set(this.ReceiptUpdate,"pw_id",row.pw_id);
         this.$set(this.ReceiptUpdate,"pw_code",row.pw_code);
         this.$set(this.ReceiptUpdate,"pw_client_property",row.pw_client_property);
         this.$set(this.ReceiptUpdate,"pw_number",row.pw_number);
         this.$set(this.ReceiptUpdate,"pw_storage_date",row.pw_storage_date);
         this.$set(this.ReceiptUpdate,"pw_operators",row.pw_operators);
         this.$set(this.ReceiptUpdate,"auditStatus",row.auditStatus);
    },
    
    //从表添加
    FromUpdateSubmit(){
      $http.post('WareHousing/WaregAdd',{
        pro_warehousingpw_id:this.SelectPurChaseID,
        wf_sing_model:this.EditUpdate.wf_sing_model,
        wf_redserial_number:this.EditUpdate.wf_redserial_number,
        wf_redunit:this.EditUpdate.wf_redunit,
        wf_storage:this.EditUpdate.wf_storage,
        wf_raw_material:this.EditUpdate.wf_raw_material,
        wf_inbound_warehouse:this.EditUpdate.wf_inbound_warehouse,
        isDeleted:false
      })
      .then(res=>{
        if(res){
          this.$message.success('添加成功！');
          this.EditUpdate.wf_sing_model="";
          this.EditUpdate.wf_redserial_number="";
          this.EditUpdate.wf_redunit="";
          this.EditUpdate.wf_storage="";
          this.EditUpdate.wf_raw_material="";
          this.fetchUpaheModeFrom();
          this.isUpdateProductVisible=false;
        }else{
          this.$message.error('添加失败！请重新添加！');
        }
      })
      .catch(error => {
         this.$message.error('添加失败：' + error.message);
     })
    },

    //查看-从修改框
    UpdatePurEditFrom(row){
      if (this.ReceiptUpdate.auditStatus === true) {
        this.$message.error("删除修改：该订单已被审核，不能进行修改！");
        return;
      }
      this.isUpdateProduct=true;
      this.$set(this.FromEditUpdate,"wf_id",row.wf_id);
      this.$set(this.FromEditUpdate,"wf_sing_model",row.wf_sing_model);
      this.$set(this.FromEditUpdate,"wf_redserial_number",row.wf_redserial_number);
      this.$set(this.FromEditUpdate,"wf_redunit",row.wf_redunit);
      this.$set(this.FromEditUpdate,"wf_storage",row.wf_storage);
      this.$set(this.FromEditUpdate,"wf_raw_material",row.wf_raw_material);
      this.$set(this.FromEditUpdate,"wf_inbound_warehouse",row.wf_inbound_warehouse);
     this.$set(this.FromEditUpdate,"pro_warehousingpw_id",row.pro_warehousingpw_id);
    },

    //从表修改
    FromUpdatePur(){
        if (this.ReceiptUpdate.auditStatus === true) {
        this.$message.error("修改失败：该订单已被审核，不能进行修改！");
        return;
      }
      $http.put('WareHousing/WaregUpdate',{
        wf_id:this.FromEditUpdate.wf_id,
        wf_sing_model:this.FromEditUpdate.wf_sing_model,
        wf_redserial_number:this.FromEditUpdate.wf_redserial_number,
        wf_redunit:this.FromEditUpdate.wf_redunit,
        wf_storage:this.FromEditUpdate.wf_storage,
        wf_raw_material:this.FromEditUpdate.wf_raw_material,
        wf_inbound_warehouse:this.FromEditUpdate.wf_inbound_warehouse,
        pro_warehousingpw_id:this.FromEditUpdate.pro_warehousingpw_id

      })
      .then(res=>{
        if(res){
          this.$message.success('修改成功！');
          this.fetchUpaheModeFrom();
          this.isUpdateProduct=false;          
        }else{
          this.$message.error('修改失败！ 请重新修改！');
        }
      }).catch(error=>{
        this.$message.error('修改失败：'+error.message);
      })
    },

    //查看-从删除
    UpdatedeleteCustomer(wf_id){
         if (this.ReceiptUpdate.auditStatus === true) {
        this.$message.error("删除失败：该订单已被审核，不能进行删除！");
        return;
      }
      MessageBox.confirm('确认删除删除该条记录吗？, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        $http.delete(`WareHousing/WaregDelete/${wf_id}`)
          .then(() => {
            this.$message({
              type: 'success',
              message: '删除成功！'
            })
            this.fetchUpaheModeFrom();
          }).catch(error=>{
            this.$message.error('删除失败：'+error.message)
          })
      })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '管理员取消了删除,删除无效哦！'
          })
        })
    },
    //查看-从查询
    fetchUpaheModeFrom(){
        this.where = "pro_warehousingpw_id=" + this.SelectPurChaseID;
        $http.get('WareHousing/WarehFenYe',{
            params:{
                currentPage: this.currentPage2,
                pageSize: this.pageSize2,
                where:this.where,
            }
        }).then(res=>{
            this.chaseFrom=res.warehousingFrom;
            this.UpdateItems=res.rows;
        }).catch(error=>{
            console.error('Error fetching client data: ', error);
        })
    },
    UdateSizeChange: function(size) {
      this.pageSize2 = size;
      this.currentPage2 = 1;
      this.fetchUpaheModeFrom();
    },
    UpdateCurrentChange: function(page) {
        this.currentPage2 = page;
        this.fetchUpaheModeFrom();
    },
      //查看-从添加框
    PurFromUpdate(){
    if (this.ReceiptUpdate.auditStatus === true) {
        this.$message.error("添加失败：该订单已被审核，不能进行添加！");
        return;
      }
      this.isUpdateProductVisible=true;
      this.property();//查询物品属性
      this.fetchUnits(); //单位
      this.WarehAit();
    },
   PurOrderUpdate(){ 
        // 检查审核状态，如果为 true，则不允许修改
      if (this.ReceiptUpdate.auditStatus === true) {
        this.$message.error("修改失败：该订单已被审核，不能进行修改！");
        return;
      }
        let Cat = '0'; 
        Cat = String(this.UpdateItems);
        $http.put('WareHousing/WareUpdate',{
           pw_id: this.ReceiptUpdate.pw_id,
           pw_code:this.ReceiptUpdate.pw_code,
           pw_client_property: this.ReceiptUpdate.pw_client_property,
           pw_types:Cat,//种类
           pw_number: this.ReceiptUpdate.pw_number,
           pw_storage_date: this.ReceiptUpdate.pw_storage_date,
           pw_operators: this.ReceiptUpdate.pw_operators,

           pw_state:'0',
           pw_warehouse:"0",
           pro_warehousing_from: [{"wf_sing_model":"","wf_redserial_number":"","wf_inbound_warehouse":"","wf_redunit":"","wf_storage":0,"wf_raw_material":0}]
        })
          .then(response => {
            if (response) {
              this.$message.success('修改成功！');
                this.PurFenYe();
                this.isUpdateModalVisible = false;
            } else {
              console.log("修改的值："+this.response);
              this.$message.error('修改失败！请重试！');
            }
          }).catch(error => {
            this.$message.error('修改失败：' + error.message);
          })
    },
    //从表添加框打开
     async PurFromAdd(){
         if (this.ReceiptUpdate.auditStatus === true) {
        this.$message.error("添加失败：该订单已被审核，不能进行添加！");
        return;
      }
      this.isAddProductVisible = true;
      this.fetchUnits(); //单位
      this.WarehAit();//入库仓库
    },
     //主-添加
    async PurOrderAdd(){
      let modelclass = '0'; // 默认值为 '0'，以防止 totalItems 为 undefined 时出错
      if (this.totalItems !== undefined) {
        modelclass = this.totalItems.toString();
      }
      this.mainData={
        pw_code:this.PurAdd.pw_code,
        pw_client_property:this.PurAdd.pw_client_property,
        pw_number:this.PurAdd.pw_number,
        pw_types:modelclass,
        pw_storage_date:this.PurAdd.pw_storage_date,
        pw_operators:this.PurAdd.pw_operators,
        pw_state:"0",
        pw_warehouse:"0",
        isDeleted:false,
        auditStatus: false,
        pro_warehousing_from:this.allData
      };
      $http.post('WareHousing/WareAdd', this.mainData)
        .then(res=>{
          if(res){
            this.$message.success('添加成功！');
            this.PurAdd.pw_code="";
            this.PurAdd.pw_client_property="";
            this.PurAdd.pw_number="";
            this.PurAdd.pw_types="";
            this.PurAdd.pw_storage_date="";
            this.PurAdd.pw_operators="";
            this.PurFenYe();
            this.isAddModalVisible = false;
          } else {
              this.$message.error('添加失败！请重新添加！');
              
            }
        }).catch(error => {
            this.$message.error('添加失败：' + error.message);
      })
    },
    PurHandleClose(done){
      this.allData=[];
      this.testArr=[];
      this.totalItems=0;
      done();
  },
    //虚拟数据
    SubmitModelForm() {
      if(this.testArr.length>0){
        this.allData = this.testArr;
      }
      // 将表单数据添加到暂时保存数据的数组中
      this.allData.push({
        wf_sing_model: this.from.wf_sing_model,
        wf_redserial_number: this.from.wf_redserial_number,
        wf_redunit: this.from.wf_redunit,
        wf_storage: this.from.wf_storage,
        wf_raw_material: this.from.wf_raw_material,
        wf_inbound_warehouse: this.from.wf_inbound_warehouse,
        index: this.allData.length // 保存当前数据项的下标
      }),
      // 清空表单数据
        this.from.wf_sing_model = '';
        this.from.wf_redserial_number = '';
        this.from.wf_redunit = '';
        this.from.wf_storage = '';
        this.from.wf_raw_material = '';
        this.from.wf_inbound_warehouse = '';
        this.currentPage1 = 1;

    // 将 allData 的值深拷贝给 testArr
      this.testArr = JSON.parse(JSON.stringify(this.allData));
      // 更新总条目数
      this.totalItems = this.allData.length;
      // 提示用户添加成功
      this.$message.success('添加成功！');
      this.isAddProductVisible = false; // 关闭对话框 
      this.End();
      // 输出数组的最后一个元素的索引
      console.log('数组最后一个元素的索引:', this.allData.length);
      console.log(JSON.stringify(this.allData));
  },
    //虚拟删除
    deleteCustomer(index) {
  // 首先确保下标在合法范围内
  if (index >= 0 && index < this.allData.length) {
    // 从数组中删除指定下标的元素
    this.allData.splice(index,1 );
    // 更新总条目数
    this.totalItems = this.allData.length;
    // 深拷贝 allData 的值给 testArr
    this.testArr = JSON.parse(JSON.stringify(this.allData));
    // 提示用户删除成功 
    this.$message.success('删除成功！');
  } else {
    // 如果下标不在合法范围内，给出相应的提示
    this.$message.error('无法删除，下标越界！');
  }
  },
     handleSizeChange: function(size) {
      this.pageSize1 = size;
      this.currentPage1 = 1;
      this.End();
    },
    handleCurrentChange: function(page) {
      this.currentPage1 = page;
      this.End();
    },

    },
    mounted(){
      this.PurFenYe();//主分页查询
      this.GouPur();
      this. fetch();
      this.Opers();
      this.ImgerFrom(); //添加产品名称
    },
};
</script>
<style scoped src="../CSS/Purchase.css"></style>
<style>
  /*表格单元格中的文本内容都将水平居中显示*/
  .centered-table .el-table__cell {
      text-align: center;
  }
  /*表格标题背景变色*/
  .centered-table .el-table__header th {
    background-color: #eeeeee;; /* 设置标题行的背景色 */
    color: #333; /* 设置标题行的文字颜色 */
  }
  
  .customer-list {
    background-color: #ffffff;
    padding: 20px;
  }
  
  /*按钮的样式*/
  .add-button {
    background-color: #4FC1B0;
    color: #ffffff;
  }
  
  .pagination {
    text-align: center;
    margin-top: 20px;
  }
  
  .add-button-bottom-right {
    position: absolute;
    bottom: 0;
    top:140px; /* 将按钮相对于父容器顶部定位 */
    right: 100px;
    margin: 20px; /* 调整按钮与分割线的距离 */
  }
  .pagination-info {
    margin-bottom: 10px;
    text-align: right; /* 将当前显示条数等信息向右对齐 */
  }
  /* 调整对话框样式 */
  .el-dialog__body {  
    padding: 0px 10px 20px 10px; /* 调整内边距 */
  }
  /* 模态框 */
  .qw{
     position: fixed;
    top: -2%;
    left: 10%;
    height: 700px; 
    overflow: hidden;
  }
  .ee{
      border-color: #4FC1B0;
  }

  .form-items-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 0 20px;
    /* 两边留出20px的空隙 */
}


/* 设置文本框的样式 */
.el-form-item__content {

    flex-grow: 1;
}

.form-item {
    flex: 0 0 calc(25% - 40px);
    /* 减去两侧各20px的空隙 */
    max-width: 250px;
    /* 设置文本框的最大宽度 */
    margin: 10px 0;
    /* 上下留出10px的空隙 */
}

.el-form-item__label {
    width: 120px;
    /* 可以调整标签的宽度 */
    text-align: right;
    padding-right: 10px;
}

@media (max-width: 800px) {
    .form-item {
        flex-basis: 100%;
        margin: 10px 0;
    }
}

.button-container {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    /* 垂直居中 */
    height: 100%;
    /* 确保按钮容器占据整个高度 */
    padding-top: 10px;
    float: left;
}

.custom-button {
    display: flex;
    align-items: center;
    /* 垂直居中 */
    justify-content: center;
    /* 水平居中 */
    background-color: #1ABC9C;
    width: 60px;
    height: 20px;
    color: #fff;
    font-size: 12px;
    top: -10px;
    border: none;
}

.custom-form {
    margin: 20px;
}

.kuang {
    width: 60px;
    font-size: small;
}

.orange-button {
    font-size: small;
}

.addmodel {
    left: 120px;
}

.caoz {
    width: 70px;
    font-size: small;
}
  </style>